package Work20241116;

import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/16
 */
public class Demo17 {
    //22、输入一个任意位数的正整数，打印出它是几位数。（使用while和do-while循环）
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正整数:");
        int num = sc.nextInt();
        int count = 0; //位数计数器
        while (num != 0) {
            num /= 10;
            count++;
        }
        System.out.println("共有" + count + "位");
        System.out.println("=======do-While==========");
        System.out.println("请输入一个正整数:");
        int a = sc.nextInt();
        doWhile(a);
    }

    public static void doWhile(int num){
        int count = 0;
        do{
            num /= 10;
            count++;
        }while (num!=0);
        System.out.println("do-While===共有" + count + "位");
    }
}
